package system;

public class FPSCalculate {
	private float [] FPSCal;
	public long LastTime;
	public long CurrentTime;
	public float FPSAverage;
	private int count;
	private int countFPS;

	public FPSCalculate(){
		FPSAverage=0;
		FPSCal=new float[10];
		for(int i=0;i<10;i++){
			FPSCal[i]=0f;
		}
		CurrentTime=LastTime=System.currentTimeMillis();
	}
	public void updateFPS(){
		long tmp=CurrentTime-LastTime;
		FPSCal[count]= 1000f/((float)tmp);
		count++;
		if(count>9){
			count=0;
		}
		countFPS++;
		if(countFPS<10){
			FPSAverage=FPSCal[1];
		}
		else{
			if(countFPS%10==0){
				float sum=0;
				for(int i=0;i<10;i++){
					sum+=FPSCal[i];
				}
				FPSAverage=sum/10;
			}
		}
	}

}
